package com.jp.knowledge.model;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;

import com.jp.knowledge.util.L;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jiayen on 17/4/6.
 */

public class PhoneUser {

    private String name;//姓名

    private String phone;//电话

    public PhoneUser(){

    }

    public PhoneUser(String name, String number) {
        this.name=name;
        this.phone=number;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    public static List<PhoneUser> getPhoneNumberFromMobile(Context context) {
       List<PhoneUser> list = new ArrayList<>();
        Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null, null, null, null);
        //moveToNext方法返回的是一个boolean类型的数据
        while (cursor.moveToNext()) {
        //读取通讯录的姓名
//            String name = cursor.getString(cursor
//                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
//            //读取通讯录的号码
//            String number = cursor.getString(cursor
//                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
//            PhoneUser phoneInfo = new PhoneUser(name, number);
//            list.add(phoneInfo);


            Class<ContactsContract.CommonDataKinds.Phone>  clazz = ContactsContract.CommonDataKinds.Phone.class;
           Field[] fields =  clazz.getDeclaredFields();
            for (Field f:fields) {
                try {
                    String fname = f.getName();
                    String vale = cursor.getString(cursor
                            .getColumnIndex(fname));
                    L.e("======key="+fname+"=======value="+vale);
                }catch (Exception e){

                }

            }

        }
        cursor.close();
        return list;
    }
}
